package com.woniuxy.controller;

import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.User;
import com.woniuxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/userController")
public class UserController {
    @Autowired
    private UserService userService;

    //跳转登录页面
    @RequestMapping("/showLogin")
    public String showLogin(){
        return "Login";
    }

    //跳转注册页面
    @RequestMapping("/showRegister")
    public String showRegister(){
        return "register";
    }

    //跳转show页面
    @RequestMapping("/show")
    public String show(){
        return "show";
    }

    //登录验证
    @PostMapping("/login")
    @ResponseBody
    public ResponseEntity login(@RequestBody User user){
        ResponseEntity responseEntity = userService.findOne(user);
        System.out.println(responseEntity);
        return responseEntity;
    }

    //注册的用户名验证
    @PostMapping("/exist")
    @ResponseBody
    public ResponseEntity exist(@RequestBody User user){
        ResponseEntity responseEntity = userService.findOne01(user);
        return responseEntity;
    }

    //注册
    @PostMapping("/regist")
    @ResponseBody
    public ResponseEntity regist(@RequestBody User user){
        ResponseEntity responseEntity = userService.addOne(user);
        return responseEntity;
    }

    //查询所有用户信息
    @PostMapping ("/user")
    @ResponseBody
    public ResponseEntity findAll(){
        ResponseEntity responseEntity = userService.findAll();
        System.out.println(responseEntity);
        return responseEntity;

    }
}
